/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * Licensed under Simplified BSD License
 *
 *
 * @Original Author: jin Chen
 * @date: Apr 18, 2005$
 * @version: 1.0
 */
package edu.psu.geovista.app.dataloader.v1.config.model;

//import org.apache.commons.collections.CollectionUtils;

//import edu.psu.geovista.common.model.collection.CollectionUtils;



import com.thoughtworks.xstream.annotations.XStreamAlias;

import java.util.*;

@XStreamAlias("VariableData")
public class DfVariableData implements VariableData {
    
    //private Properties paths;
    private List <Path> paths;
    @XStreamAlias("SelectedVariables")
    private Set <Variable> selectedVariables;  // 
    //@XStreamUseAttribute
    private Boolean load=true;// 

    public DfVariableData() {
        this.paths =new ArrayList<Path>();
        this.selectedVariables =new HashSet <Variable> ();

    }

    public List<Path> getPaths() {
        return paths;
    }

    public void setPaths(List<Path> paths) {
        this.paths = paths;
    }

    /**
     *
     * @param pathname
     * @return
     */
     public Path getPath(String pathname){
         for (Iterator iterator = paths.iterator(); iterator.hasNext();) {
             Path path = (Path) iterator.next();
             String name = path.getName();
             if(name!=null&&name.equals(pathname) ){
                return path;
            }
         }

        return null;
    }

    public List<String> getSelectedVariableNames() {
        //Iterator<String> iterator = selectedAttributes.iterator();
        List<String> list=new ArrayList(selectedVariables.size() );
        for (Iterator iterator = list.iterator(); iterator.hasNext();) {
            Variable var = (Variable) iterator.next();
            list.add(var.getName() );
        }
        //list.addAll(selectedVariables);
        return list;
    }

    public void setSelectedVariableNames(List<String> varnames) {
        //this.selectedAttributes = selectedAttributes;
        this.selectedVariables.clear();
        for (Iterator iterator = varnames.iterator(); iterator.hasNext();) {
            String name = (String) iterator.next();
            Variable var=new Variable(name);
            selectedVariables.add(var);
        }
        //this.selectedAttributes.addAll(varnames);
    }
    public boolean isLoad() {
            return load;
        }

    public void setLoad(boolean load) {
            this.load = load;
    }
    public static Properties toProperties(List<Path> paths){
        Properties p=new Properties();
        for (Iterator iterator = paths.iterator(); iterator.hasNext();) {
            Path path = (Path) iterator.next();
            p.put(path.getName() , path.getValue() );
        }
        return p;
    }

}
